<template>
  <div class="charts-header">
    <div class="charts-header-switch">
      <div class="charts-header-title">{{ chartsValue.title }}</div>
      <div>
        <span class="switch-label">查看示例数据：</span>
        <el-switch 
          v-model="isExample"
          @change="switchSampleData"
        >
        </el-switch>
      </div>
    </div>
    
    <div class="charts-header-text">
      <i class="iconfont icon-mubiao"></i>
      <span>目标：</span>
      <span>{{ chartsValue.target }}</span>
    </div>
    <div class="charts-header-text">
      <i class="iconfont icon-jieshi"></i>
      <span>含义：</span>
      <span>{{ chartsValue.description }}</span>
    </div>
  </div>
</template>
<script>
import { computed, watch, ref } from 'vue';
export default {
  name: 'charts-header',
  props: {
    chartsValue: {
      type: Object,
      default: () => ({}),
    },
    chartOption: {
      type: Object || String,
    }
  },
  setup(props, { emit }) {
    const isExample = ref(false)
    const chartOption = computed(() => {
      return props.chartOption
    })
    watch(chartOption, () => {
      isExample.value = props.chartOption?.isExample || false
    })

    const switchSampleData = value => {
      const newValue = {
        ...props.chartOption,
        isExample: value
      }
      emit('switch', newValue)
    }

    return {
      isExample,
      switchSampleData
    }
  }
};
</script>
<style lang="scss" scoped>
.charts-header {
  min-height: 100px;
  line-height: 24px;
  padding: 15px;
  margin-bottom: 12px;
  border-radius: 4px;
  background-color: #fff;

  .charts-header-switch {
    display: flex;
    justify-content: space-between;
    .switch-label {
      font-size: 12px;
      color: #8c8c8c;
    }
    .charts-header-title {
      font-size: 16px;
      font-weight: bold;
      color: #262626;
      margin-bottom: 5px;
    }
  }

  .charts-header-text {
    color: #262626;
    font-size: 12px;

    i {
      margin-right: 5px;
      vertical-align: bottom;
    }

    span:last-child {
      color: #8c8c8c;
    }

    .icon-mubiao {
      color: #FF7043;
    }

    .icon-jieshi {
      color: $color-primary-light-6;
    }
  }
}
</style>
